#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
using namespace std;
int main()
{
    int fd = -1, newfd = -1;
    fd = open("txt", O_WRONLY | O_CREAT, 0644);
    cout << "fd==" << fd << endl;
    newfd = fcntl(fd, F_DUPFD, 0);
    cout << "newfd==" << newfd << endl;
    write(fd, "chenbiaoren", 12);
    write(newfd, "hehehe", 6);
    close(fd);
    close(newfd);
    return 0;
}
